<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../css/public.css" media="all">
    <link rel="stylesheet" href="../css/expenses.css" media="all">
</head>
<style>
    .layui-inline{margin-bottom: 15px;}
</style>
<body>
<div class="layuimini-container">
    <div class="title">
        <em></em>
        <h3>费用支付</h3>
    </div>

    <!--<div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
        <ul class="layui-tab-title">
            <li class="layui-this">所有订单</li>
            <li>待支付</li>
        </ul>
    </div> -->

    <form class="layui-form padding15_10" action="">
        <div class="layui-inline">
            <div class="layui-input-inline">
                <input type="text" name="beginDate" id="beginDate" placeholder="申请开始时间" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <div class="layui-input-inline">
                <input type="text" name="endDate" id="endDate" placeholder="申请结束时间" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <div class="layui-input-inline">
                <input type="text" name="orderId" placeholder="请输入订单号" class="layui-input">
            </div>
        </div>

        <div class="layui-inline">
            <div class="layui-input-inline">
                <select name="interest" lay-filter="aihao">
                    <option value="">订单状态</option>
                    <option value="1">已完成</option>
                    <option value="2">已取消</option>
                </select>
            </div>
        </div>

        <div class="layui-inline">
            <div class="layui-input-inline">
                <button class="layui-btn" lay-submit="" lay-filter="searchBtn">查询</button>
                <button type="reset" class="layui-btn layui-btn-primary">清空</button>
            </div>
        </div>
    </form>
    <form class="layui-form layui-form-padding" action="">
        <div class="layui-inline">
            <div class="layui-input-inline">
                <button type="button" class="layui-btn layui-btn-primary" lay-submit="" lay-filter="demo1">新增订单</button>
            </div>
        </div>
    </form>
    <div class="layuimini-main">
        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

    </div>
    <script type="text/html" id="staBar">
       {{# if(d.orderType == '0'){ }}
           {{# if(d.approveStatus == '0'){ }}
                <span style="color: #00a2d4">发放待审核中</span>
           {{# }else if(d.approveStatus == '1'){ }}
                <span style="color: #009688">审核通过</span>
           {{# }else if(d.approveStatus == '2'){ }}
                <span style="color: red">审核不通过</span>
           {{# } }}
        {{# }else if(d.orderType == '1'){ }}
            <span style="color: #009688">已完成</span>
        {{# }else if(d.orderType == '2'){ }}
            <span style="color: red">取消</span>
        {{# } }}
    </script>

</div>
<script src="../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script>
    var this_ = '',tableIns;
    layui.use(['form', 'table','jquery','element','laydate','tfApi'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            $ = layui.jquery,
            this_ = $,
            element = layui.element,
            laydate = layui.laydate,
            API = layui.tfApi;

        tableIns = table.render({
            elem: '#currentTableId',
            url: API.CURL + '/seller/qryProvideOrder',
            cellMinWidth: 60,
            method: "POST",
            contentType: 'application/json',
            xhrFields: {withCredentials: true},crossDomain: true,
            request:{
                pageName: "page",
                limitName : "pageSize"
            },
            parseData: function(res){ //res 即为原始返回的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": res.data.total, //解析数据长度
                    "data": res.data.details, //解析数据列表
                };
            },
            /*where:{
                "page": "0",
                "pageSize": "10"
            },*/
            cols: [[
                {field: 'orderId', title: '订单号'},
                {field: 'applyTime', title: '申请时间'},
                {field: 'endTime', title: '完成时间',templet:function (d) {
                    var _s = (d.orderType == "0") ? '' : d.endTime;
                    return _s;
                }},
                {field: 'sellerName', title: '商户名称'},
                {field: 'provideList', title: '发放清单',templet:function (d) {
                        var html = '<a href="javascript:;" style="color: #1E9FFF;" onclick=window.open("'+d.provideList+'")>人员名单下载</a>';
                        return html;
                    }},
                {field: 'serviceName',  title: '服务商名称'},
                {field: 'realAmount', title: '实发金额',templet: function (d) {
                    var _s = API.numFun(d.realAmount);
                        return '<b>'+_s+'</b>';
                }},
                {field: 'orderType', title: '订单状态', templet: "#staBar"}
            ]],
            page: true,
            //skin: 'line'
        });
        //监听提交
        form.on('submit(searchBtn)', function (data) {

            var beginDate = $("#beginDate").val(),
                endDate = $("#endDate").val(),
                orderId = $("input[name='orderId']").val(),
                interest = $("select[name='interest']").val();
            if(beginDate == ''){
                beginDate = getlastmonth() + ' 00:00:00';
            }
            if(endDate == ''){
                endDate = getcurrent() + ' 23:59:59';
            }
            let query_y = {
                page: {
                    curr: 1 //重新从第 1 页开始
                }
                , done: function (res, curr, count) {
                    //完成后重置where，解决下一次请求携带旧数据
                    //   this.where = {};
                }
            };

            query_y.where = {
                "beginDate" : beginDate,
                "endDate" : endDate,
                "orderId" : orderId,
                "interest" : interest
            };
            tableIns.reload(query_y);
            return false;
        });

        form.on('submit(demo1)', function (data) {
            var index = layer.open({
                title: '新增订单',
                type: 2,
                shade: 0.2,
                maxmin:true,
                shadeClose: true,
                area: ['100%', '100%'],
                content: '../page/table/add.html',
                end:function(){
                    location.reload();
                }
            });
            $(window).on("resize", function () {
                layer.full(index);
            });
            return false;
        });

        //日期
        laydate.render({
            elem: '#beginDate'
            ,type: 'datetime'
        });
        laydate.render({
            elem: '#endDate'
            ,type: 'datetime'
        });

        //将个数位日期转为07
        function p(s) {
            return s < 10 ? '0' + s : s;
        }

        function getcurrent() {
//将一个月的日期填入搜索框
            var currentYear=new Date().getFullYear();
            var currentMonth=new Date().getMonth()+1;
            var currentDate=new Date().getDate();
            var current =currentYear+"-"+p(currentMonth)+"-"+p(currentDate);
            return current;
        }


        function getlastmonth() {
            var currentYear=new Date().getFullYear();
            var currentMonth=new Date().getMonth()+1;
            var lastMonth=new Date().getMonth();
            var currentDate=new Date().getDate();
            var prevCurrentYear=0;
            var prevCurrentMonth=0;
            if(currentMonth==0){
                prevCurrentYear=currentYear-2;
                prevCurrentMonth=12;
            }else{
                prevCurrentYear=currentYear-1;
                prevCurrentMonth=currentMonth;
            }
            var lastmonth=prevCurrentYear+"-"+p(prevCurrentMonth)+"-"+p(currentDate)
            return lastmonth;
        }

    });
    function show_img(t) {
        console.log("----->",t)
        var t = this_(t).find("img");
        //页面层
        layer.open({
            type: 1,
            skin: 'layui-layer-rim', //加上边框
             area: ['80%', '80%'], //宽高
            shadeClose: true, //开启遮罩关闭
            end: function (index, layero) {
                return false;
            },
            content: '<div style="text-align:center"><img src="' + this_(t).attr('src') + '" /></div>'
        });
    }
</script>

</body>
</html>